package com.sunnyweather.android.ui.ui.home


import android.os.Bundle
import android.view.View
import android.widget.RadioGroup
import com.blankj.utilcode.util.ToastUtils
import com.sunnyweather.android.R
import com.sunnyweather.android.ui.adapter.ViewBindingSampleAdapter
import com.sunnyweather.android.utils.BaseFragment
import com.zhpan.bannerview.BannerViewPager
import com.zhpan.bannerview.annotation.APageStyle
import com.zhpan.bannerview.constants.PageStyle
import com.zhpan.indicator.enums.IndicatorSlideMode

class HomeFragment : BaseFragment() {

    private var mViewPager: BannerViewPager<Int>? = null

    override val layout: Int
        get() = R.layout.fragment_home

    override fun initTitle() {}

    override fun initView(savedInstanceState: Bundle?, view: View) {
        mViewPager = view.findViewById(R.id.banner_view)
        with(mViewPager) {
            this?.setIndicatorSlideMode(IndicatorSlideMode.WORM)
                ?.setIndicatorSliderColor(
                    getColor(R.color.gray_1),
                    getColor(R.color.tkx_like)
                )
                ?.setIndicatorStyle(1)
                ?.setIndicatorSliderRadius(
                    resources.getDimensionPixelOffset(R.dimen.dp_4),
                    resources.getDimensionPixelOffset(R.dimen.dp_4)
                )
                ?.setLifecycleRegistry(lifecycle)
                ?.setOnPageClickListener { view: View, position: Int ->
                    pageClick(
                        view,
                        position
                    )
                }
                ?.setAdapter(ViewBindingSampleAdapter(resources.getDimensionPixelOffset(R.dimen.dp_8)))
                ?.setInterval(5000)
        }

        setupBanner(PageStyle.MULTI_PAGE_OVERLAP)
    }

    private fun pageClick(view: View, position: Int) {
        if (position != mViewPager!!.currentItem) {
            mViewPager!!.setCurrentItem(position, true)
        }
        ToastUtils.showShort("position:$position")
    }


    private fun setupBanner(@APageStyle pageStyle: Int) {
        mViewPager
            ?.setPageMargin(resources.getDimensionPixelOffset(R.dimen.dp_15))
            ?.setRevealWidth(resources.getDimensionPixelOffset(R.dimen.dp_10))
            ?.setPageStyle(pageStyle)
            ?.create(getPicList(5))
    }


}